package com.playball.lottery.frm.yhzx;

import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.playball.lottery.ApplicationData;
import com.playball.lottery.R;
import com.playball.lottery.base.BaseActivity;
import com.playball.lottery.nt.GetRequestParams;
import com.playball.lottery.util.ConvertJsonToList;

import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import java.util.HashMap;
import java.util.Map;


/**
 * 安全中心
 * 
 * @author tanglizhong
 * @version 2014-3-26 上午10:37
 */
public class SecurityCenterActivity extends BaseActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.yhzx_securitycenter);

		titleBar();
		initView();
		initData();
	}

	/**
	 * 初始化数据
	 */
	private void initData() {
		 AsyncLoader task = new AsyncLoader();
		 task.execute("107");
	}

	/**
	 * 初始化组件
	 */
	private void initView() {
		View view_sc_person_info = findViewById(R.id.view_sc_person_info);
		view_sc_person_info.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(SecurityCenterActivity.this, ScPersonActivity.class);
				startActivity(intent);
			}
		});
		View view_sc_telephone_bind = findViewById(R.id.view_sc_telephone_bind);
		view_sc_telephone_bind.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(SecurityCenterActivity.this, ScTelephoneActivity.class);
				startActivity(intent);
			}
		});
		View view_sc_login_pwd = findViewById(R.id.view_sc_login_pwd);
		view_sc_login_pwd.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(SecurityCenterActivity.this, ScLoginPwdActivity.class);
				startActivity(intent);
			}
		});
		View view_sc_security_question = findViewById(R.id.view_sc_security_question);
		view_sc_security_question.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(SecurityCenterActivity.this, ScQuestionActivity.class);
				startActivity(intent);
			}
		});
		View view_sc_bank_card = findViewById(R.id.view_sc_bank_card);
		view_sc_bank_card.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(SecurityCenterActivity.this, ScBankCardActivity.class);
				startActivity(intent);
			}
		});
		View view_sc_withdraw_pwd = findViewById(R.id.view_sc_withdraw_pwd);
		view_sc_withdraw_pwd.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(SecurityCenterActivity.this, ScWithdrawPwdActivity.class);
				startActivity(intent);
			}
		});
	}

	public void onResume() {
		super.onResume();
		
	}

	public void onPause() {
		super.onPause();
		
	}

	// TitleBar标题栏
	public void titleBar() {
		TextView info = (TextView) findViewById(R.id.top_title_info);
		info.setText(R.string.yhzx_security_center);
		TextView back = (TextView) findViewById(R.id.top_title_back);
		back.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
	}

	/**
	 * 获取用户基本信息
	 */
	 private class AsyncLoader extends AsyncTask<String, Integer, String> {

	 @Override
	 protected String doInBackground(String... params) {
	 String action = params[0];
	 String strResult;

	 JSONObject param = new JSONObject();
	 String UserID = ApplicationData.getInstance().getUserID();
	 strResult = GetRequestParams.getRequestUserIDResult(param.toString(),
	 UserID,action, getApplicationContext());
	 return strResult;
	 }
	 @Override
	 protected void onPostExecute(String result) {
	 try {
	 if(null != result) {
	 JSONTokener jsonParser = new JSONTokener(result);
	 JSONObject js = (JSONObject) jsonParser.nextValue();

	 if(js.getInt("Code") == 0) {
	 Map<String, Object> map = new HashMap<String, Object>();
	 map = ConvertJsonToList.getMap(js.getString("Data"));

	 ApplicationData.getInstance().setRealName(map.get("RealName").toString());
	 ApplicationData.getInstance().setCardNum(map.get("BankCardNumber").toString());
	 ApplicationData.getInstance().setMobile(map.get("Mobile").toString());
	 ApplicationData.getInstance().setBankName(map.get("BankName").toString());
	 ApplicationData.getInstance().setIDCardNumber(map.get("IDCardNumber").toString());
	 ApplicationData.getInstance().setIsMobileValied(map.get("IsMobileValied").toString().equals("true"));
	 //ApplicationData.getInstance().setSecurityQuestion(map.get("SecurityQuestion").toString());
		 if("true".equals(map.get("IsPayPwd").toString())){
			 ApplicationData.getInstance().setIsPayPwd(1);
		 }else {
			 ApplicationData.getInstance().setIsPayPwd(0);
		 }

	 }
	 }
	 } catch (JSONException e) {
	 e.printStackTrace();
	 }
	 }

	 }
}
